import { createRouter, createWebHashHistory } from 'vue-router'
import { useUserStore } from '@/store/user'
const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home.vue' /**WebChunkName:"Home" */),
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue' /**WebChunkName:"About" */),
  },
  {
    path: '/course',
    name: 'Course',
    component: () => import('../views/Course.vue' /**WebChunkName:"Course" */),
  },
  {
    path: '/course/detail',
    name: 'Detail',
    component: () => import('../views/Detail.vue' /**WebChunkName:"Detail" */),
  },
  {
    path: '/course-play/:courseId/:chapterId',
    name: 'course-play',
    component: () =>
      import('../views/CoursePlay.vue' /**WebChunkName:"CoursePlay" */),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue' /**WebChunkName:"Login" */),
  },
  {
    path: '/cart',
    name: 'Cart',
    component: () => import('../views/Cart.vue' /**WebChunkName:"Cart" */),
    beforeEnter(to, from, next) {
      if (useUserStore().userInfo.id) {
        next()
      } else {
        next('/login')
      }
    },
  },
  {
    path: '/confirmOrder',
    name: 'ConfirmOrder',
    component: () =>
      import('../views/ConfirmOrder.vue' /**WebChunkName:"ConfirmOrder" */),
    beforeEnter(to, from, next) {
      if (useUserStore().userInfo.id) {
        next()
      } else {
        next('/login')
      }
    },
  },
]

const router = createRouter({
  routes,
  history: createWebHashHistory(),
})

export default router
